package cn.itcast.service.company.impl;


import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {

    @Autowired
    private CompanyDao companyDao;

    //查询全部企业
    @Override
    public List<Company> findAll() {
        List<Company> list = companyDao.findAll();
        return list;
    }


    //保存添加企业
    @Override
    public void save(Company company) {
        //补充uuid作为主键
        company.setId(UUID.randomUUID().toString());
        //添加企业
        companyDao.save(company);
    }

    //保存修改企业
    @Override
    public void update(Company company) {
        companyDao.update(company);
    }

    //根据企业的id查找企业
    @Override
    public Company findById(String id) {
        Company company = companyDao.findById(id);
        return company;
    }


    //根据id删除企业
    @Override
    public void delete(String id) {
        companyDao.delete(id);
    }


    //分页查询企业
    @Override
    public PageInfo<Company> findByPage(Integer pageNum, Integer pageSize) {
        //1.设置当前页与页面大小
        PageHelper.startPage(pageNum,pageSize);

        //2.查询全部企业
        List<Company> list = companyDao.findAll();

        //3. 构建pageInfo对象
        PageInfo<Company> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }
}
